const mongoose = require("./db");
const { getId } = require("../utils/getMethods");

const regionListSchema = new mongoose.Schema({
  regionId: {
    type: Number,
    default: () => getId,
  },
  regionName: {
    type: String,
    required: true,
  },
  leaderId: [
    {
      type: mongoose.Types.ObjectId,
      ref: "leaderAddress",
    },
  ],
});

const leaderAddressContentSchema = new mongoose.Schema({
  id: {
    type: Number,
    default: () => getId,
  },
  takeName: {
    type: String,
    required: true,
  },
  location: {
    type: Object,
  },
  storePath: {
    type: String,
    required: true,
  },
  detailAddress: {
    type: String,
    required: true,
  },
  distance: {
    type: Number,
    required: true,
  },
});

const leaderAddressSchema = new mongoose.Schema(
  {
    userId: [
      {
        type: mongoose.Types.ObjectId,
        ref: "user",
      },
    ],
    leaderId: {
      type: Number,
      unique: true,
      default: () => getId,
    },
    leaderName: String,
    leaderPhone: String,
    takeName: {
      type: String,
      required: true,
    },
    detailAddress: {
      type: String,
      required: true,
    },
    longitude: {
      type: Number,
    },
    latitude: {
      type: Number,
    },
    storePath: {
      type: String,
      required: true,
    },
  },
  { versionKey: false }
);

const regionListModel = mongoose.model(
  "regionList",
  regionListSchema,
  "regionList"
);
const leaderAddressContentModel = mongoose.model(
  "leaderAddressContent",
  leaderAddressContentSchema,
  "leaderAddressContent"
);
const leaderAddressModel = mongoose.model(
  "leaderAddress",
  leaderAddressSchema,
  "leaderAddress"
);

// leaderAddressModel.create({
//   userId: [
//     "6583f4535709833039967cc6",
//     "6583f87dffb681889d36a22e",
//     "6583f988f169f133fa0d28ca",
//   ],
//   leaderName: "三里河路提货点",
//   leaderPhone: "15533335892",
//   takeName: "三里河路提货点",
//   detailAddress: "三里河路19号院",
//   longitude: 104.066284134167,
//   latitude: 30.5729383416216,
//   storePath:
//     "https://ts1.cn.mm.bing.net/th/id/R-C.d2c49348770d32c264edf4937f82f901?rik=zOEUVUcbuGjC9Q&riu=http%3a%2f%2fsociety.yunnan.cn%2fpic%2f003%2f019%2f302%2f00301930226_a5950c64.jpg&ehk=Z334suwfeOziKg5q6MhexIMJhRb8A4YnE4tXuLDEvY8%3d&risl=&pid=ImgRaw&r=0",
// });

module.exports = {
  leaderAddressModel,
  leaderAddressContentModel,
  regionListModel,
};
